//
//  MLAShopFoodRightCell.m
//  MagicLampApp
//
//  Created by Zheng on 2019/4/4.
//  Copyright © 2019 zheng.magic.lamp.app. All rights reserved.
//

#import "MLAShopFoodRightCell.h"

@implementation MLAShopFoodRightCell

- (void)setModel:(MLAShopFoodRightModel *)model {
    _model = model;
    
    [_foodImgv sd_setImageWithURL:[NSURL URLWithString:_model.product_imgs]];
    _nameLbl.text = _model.name;
    _priceLbl.text = [NSString stringWithFormat:@"¥ %@",_model.price];
    _saleNumLbl.text = [NSString stringWithFormat:@"销量%@",_model.sales];
    
    _numLbl.text = _model.num;
    if (_model.num.integerValue == 0)
    {
        _subBtn.hidden = YES;
        _numLbl.hidden = YES;
    } else {
        _subBtn.hidden = NO;
        _numLbl.hidden = NO;
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];

    _subBtn.hidden = YES;
    _numLbl.hidden = YES;

    [_foodImgv mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.offset(10);
        make.width.height.offset(90);
    }];
    
    [_nameLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.foodImgv.mas_right).offset(20);
        make.top.equalTo(self.foodImgv).offset(5);
    }];
    
    [_saleNumLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLbl);
        make.top.equalTo(self.nameLbl.mas_bottom).offset(3);
    }];
    
    [_priceLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLbl);
        make.bottom.equalTo(self.foodImgv).offset(-5);
    }];
    
    [_addBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-15);
        make.width.height.offset(20);
        make.centerY.equalTo(self.priceLbl);
    }];
    
    [_numLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.addBtn.mas_left).offset(-8);
        make.centerY.equalTo(self.addBtn);
    }];
    
    [_subBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.numLbl.mas_left).offset(-8);
        make.centerY.equalTo(self.addBtn);
    }];
    
}

- (IBAction)addBtnAction:(id)sender {
    if (_addClickBlock) {
        _addClickBlock(_model);
    }
}


- (IBAction)subBtnAction:(id)sender {
    if (_subClickBlock) {
        _subClickBlock(_model);
    }
}


@end
